local joy__lianshi = fk.CreateSkill {

  name = "joy__lianshi",

  tags = { Skill.Compulsory, },

}



joy__lianshi:addEffect(fk.AfterCardsMove, {
  name = "joy__lianshi",
  frequency = Skill.Compulsory,
  events = { fk.AfterCardsMove },
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(joy__lianshi.name) then
      local mark = player:getTableMark( "@joy__lianshi")
      local suits, num = {}, 0
      for _, move in ipairs(data) do
        if move.from==player and (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResonpse or move.moveReason == fk.ReasonDiscard) then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if card.suit ~= Card.NoSuit and not table.contains(mark, card:getSuitString(true)) and (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerHand) then
              num = math.max(num, card.number)
              table.insertIfNeed(suits, card:getSuitString(true))
            end
          end
        end
      end
      if #suits > 0 then
        event:setCostData(self, {suits, num})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits, num = table.unpack(event:getCostData(self))
    local mark = player:getTableMark( "@joy__lianshi")
    table.insertTable(mark, suits)
    room:setPlayerMark(player, "@joy__lianshi", mark)
    if #mark == 4 then
      player:drawCards(1, joy__lianshi.name)
      room:recover { num = num, skillName = joy__lianshi.name, who = player, recoverBy = player}
      room:setPlayerMark(player, "@joy__lianshi", 0)
    end
  end,
})

joy__lianshi:addEffect("maxcards", {
  name = "#joy__lianshi_maxcards",
  fixed_func = function(self, player)
    if player:hasSkill(joy__lianshi.name) then
      return 5
    end
  end
})

return joy__lianshi